<?php
function listSanPham($idChungLoai)
{
	if($idChungLoai==null)
	{
		$query='select * from sanpham';
	}
	else{
		$query='select * from sanpham where idCL='.$idChungLoai;
	}
	$result=mysql_query($query);
	if(!$result){
		return false;
	}
	else{
		$listSanPham=array();
		while($row=mysql_fetch_array($result,MYSQL_ASSOC))
		{
			$listSanPham[]=$row;
		}
	}
	return $listSanPham;
}
function getSanPham($idSanPham)
{
	$query='select * from sanpham where idSP='.$idSanPham;
	$result=mysql_query($query);
	if(!$result){
		return false;
	}
	else{
		return mysql_fetch_row($result);
	}
}
function themSanPham($idCL,$tenSanPham,$moTa,$gia,$urlHinh,$soLanXem,$soLuongTonKho,$ghiChu,$soLanMua,$anHien,$ngayCapNhat)
{
	$query='insert into sanpham(idCL,TenSP,MoTa,Gia,UrlHinh,SoLanXem,SoLuongTonKho,GhiChu,SoLanMua,AnHien,NgayCapNhat) values ('.$idCL.',"'.$tenSanPham.'","'.$moTa.'",'.$gia.',"'.$urlHinh.'",'.$soLanXem.','.$soLuongTonKho.',"'.$ghiChu.'",'.$soLanMua.','.$anHien.','.$ngayCapNhat.')';
	if(!mysql_query($query)){
		echo mysql_error();
		//return false;
	}
	else{
		return true;
	}
}
function xoaSanPham($idSanPham)
{
	$query='delete from sanpham where idSP='.$idSanPham;
	if(!mysql_query($query)){
		return false;
	}
	else{
		return true;
	}
}
function suaSanPham($idSanPham,$idCL,$tenSanPham,$moTa,$gia,$urlHinh,$soLanXem,$soLuongTonKho,$ghiChu,$soLanMua,$anHien,$ngayCapNhat)
{
	$query='update sanpham set idCL='.$idCL.', TenSP="'.$tenSanPham.'", MoTa="'.$moTa.'", Gia='.$gia.', UrlHinh="'.$urlHinh.'", SoLanXem='.$soLanXem.', SoLuongTonKho='.$soLuongTonKho.', GhiChu="'.$ghiChu.'", SoLanMua='.$soLanMua.', AnHien='.$anHien.', NgayCapNhat='.$ngayCapNhat.' where idSP='.$idSanPham;
	if(!mysql_query($query)){
		//return false;
		echo mysql_error();
	}
	else{
		return true;
	}
}
?>